package com.example.javamaday.offer;

import com.example.javamaday.leetcode.base.ListNode;

import java.util.Stack;

public class GetOffer06 {

    public static void main(String[] args) {

    }

    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        while (head != null) {
            System.out.println("压栈：" + head.val);
            stack.push(head.val);
            head = head.next;
        }
        System.out.println("Stack Size = " + stack.size());
        int[] result = new int[stack.size()];
        int length = stack.size();
        for (int i = 0; i < length; i++) {
            System.out.println("出栈：" + stack.peek());
            result[i] = stack.pop();
        }
        return result;
    }
}
